package com.yrmao.chiefenergyofficer.ui;

import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.FrameLayout;

import com.yrmao.chiefenergyofficer.R;
import com.yrmao.chiefenergyofficer.ui.common.TransparentActivity;
import com.yrmao.chiefenergyofficer.ui.fragment.Left_DrawerFragment;
import com.yrmao.chiefenergyofficer.ui.fragment.MainFragment;

public class MainActivityTool extends TransparentActivity {
    private DrawerLayout mDrawerLayout;
    private FrameLayout mLeftLayout, mRightLayout;
    private ActionBarDrawerToggle mDrawerToggle;
    private Fragment mLiftDraWerFragment;
    private View showView;
    private Toolbar mToolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ac_main);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                getWindow().setStatusBarColor(getResources().getColor(R.color.white));
            }
        }
        initview();
        initDrawerToggle();
        init();
    }

    private void init() {
        mLiftDraWerFragment = new Left_DrawerFragment();
        getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, new MainFragment()).commit();
        getSupportFragmentManager().beginTransaction().replace(R.id.left_drawer, mLiftDraWerFragment).commit();
    }

    private void initDrawerToggle() {
        //创建返回键，并实现打开关/闭监听
        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.open, R.string.close) {
            @Override
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                showView = drawerView;
                if (drawerView == mLeftLayout) {
                } else {
                }
            }

            @Override
            public void onDrawerClosed(View drawerView) {
                super.onDrawerClosed(drawerView);
                mToolbar.setTitle(getResources().getString(R.string.title_frastpage));
            }
        };
        mDrawerToggle.syncState();
        mDrawerLayout.setDrawerListener(mDrawerToggle);
    }

    private void initview() {
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_main);
        mLeftLayout = (FrameLayout) findViewById(R.id.left_drawer);
        mRightLayout = (FrameLayout) findViewById(R.id.right_drawer);
        mToolbar = (Toolbar) findViewById(R.id.toolbar_base);
        mToolbar.setTitleTextColor(getResources().getColor(R.color.black));
        mToolbar.setBackgroundColor(getResources().getColor(R.color.white));

        mToolbar.setTitle(getResources().getString(R.string.title_frastpage));
        showView = mLeftLayout;
        //禁用抽屉
//        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    }
}
